# trace generated using paraview version 5.9.1

#### import the simple module from the paraview
from paraview.simple import *
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()

folder = 'F:\\QCH_ignition_model\\python\\'+'pics0719_1431\\'
simu_num = 1
simu_iter = 1 
iter_gap = 5

# create a new 'CSV Reader'
shell_pointscsv = CSVReader(registrationName='shell_points.csv', FileName=['F:\\QCH_ignition_model\\python\\data\\shell_points_half.csv'])

# get active view
renderView1 = GetActiveViewOrCreate('RenderView')

# destroy renderView1
Delete(renderView1)
del renderView1

# get layout
layout1 = GetLayoutByName("Layout #1")

RemoveLayout(layout1)

# create new layout object 'Layout #1'
layout1_1 = CreateLayout(name='Layout #1')

# set active source
SetActiveSource(shell_pointscsv)

# Create a new 'SpreadSheet View'
spreadSheetView1 = CreateView('SpreadSheetView')
spreadSheetView1.ColumnToSort = ''
spreadSheetView1.BlockSize = 1024

# show data in view
shell_pointscsvDisplay = Show(shell_pointscsv, spreadSheetView1, 'SpreadSheetRepresentation')

# add view to a layout so it's visible in UI
AssignViewToLayout(view=spreadSheetView1, layout=layout1_1, hint=0)

# hide data in view
Hide(shell_pointscsv, spreadSheetView1)

# set active source
SetActiveSource(shell_pointscsv)

# set active source
SetActiveSource(shell_pointscsv)

# show data in view
shell_pointscsvDisplay = Show(shell_pointscsv, spreadSheetView1, 'SpreadSheetRepresentation')

# show data in view
shell_pointscsvDisplay = Show(shell_pointscsv, spreadSheetView1, 'SpreadSheetRepresentation')

# set active source
SetActiveSource(shell_pointscsv)

# show data in view
shell_pointscsvDisplay = Show(shell_pointscsv, spreadSheetView1, 'SpreadSheetRepresentation')

# create a new 'Table To Points'
tableToPoints1 = TableToPoints(registrationName='TableToPoints1', Input=shell_pointscsv)
tableToPoints1.XColumn = 'x'
tableToPoints1.YColumn = 'x'
tableToPoints1.ZColumn = 'x'

# Properties modified on tableToPoints1
tableToPoints1.YColumn = 'y'
tableToPoints1.ZColumn = 'z'

# show data in view
tableToPoints1Display = Show(tableToPoints1, spreadSheetView1, 'SpreadSheetRepresentation')

# hide data in view
Hide(shell_pointscsv, spreadSheetView1)

# update the view to ensure updated data information
spreadSheetView1.Update()

# Properties modified on spreadSheetView1
spreadSheetView1.CellFontSize = 9

# hide data in view
Hide(tableToPoints1, spreadSheetView1)

# set active source
SetActiveSource(tableToPoints1)

# show data in view
tableToPoints1Display = Show(tableToPoints1, spreadSheetView1, 'SpreadSheetRepresentation')

# show data in view
tableToPoints1Display = Show(tableToPoints1, spreadSheetView1, 'SpreadSheetRepresentation')

# destroy spreadSheetView1
Delete(spreadSheetView1)
del spreadSheetView1

RemoveLayout(layout1_1)

# create new layout object 'Layout #1'
layout1_2 = CreateLayout(name='Layout #1')

# get the material library
materialLibrary1 = GetMaterialLibrary()

# Create a new 'Render View'
renderView1 = CreateView('RenderView')
renderView1.AxesGrid = 'GridAxes3DActor'
renderView1.StereoType = 'Crystal Eyes'
renderView1.CameraFocalDisk = 1.0
renderView1.BackEnd = 'OSPRay raycaster'
renderView1.OSPRayMaterialLibrary = materialLibrary1

# show data in view
tableToPoints1Display = Show(tableToPoints1, renderView1, 'GeometryRepresentation')

# trace defaults for the display properties.
tableToPoints1Display.Representation = 'Surface'
tableToPoints1Display.ColorArrayName = [None, '']
tableToPoints1Display.SelectTCoordArray = 'None'
tableToPoints1Display.SelectNormalArray = 'None'
tableToPoints1Display.SelectTangentArray = 'None'
tableToPoints1Display.OSPRayScaleFunction = 'PiecewiseFunction'
tableToPoints1Display.SelectOrientationVectors = 'None'
tableToPoints1Display.ScaleFactor = 0.0108
tableToPoints1Display.SelectScaleArray = 'None'
tableToPoints1Display.GlyphType = 'Arrow'
tableToPoints1Display.GlyphTableIndexArray = 'None'
tableToPoints1Display.GaussianRadius = 0.00054
tableToPoints1Display.SetScaleArray = [None, '']
tableToPoints1Display.ScaleTransferFunction = 'PiecewiseFunction'
tableToPoints1Display.OpacityArray = [None, '']
tableToPoints1Display.OpacityTransferFunction = 'PiecewiseFunction'
tableToPoints1Display.DataAxesGrid = 'GridAxesRepresentation'
tableToPoints1Display.PolarAxes = 'PolarAxesRepresentation'

# add view to a layout so it's visible in UI
AssignViewToLayout(view=renderView1, layout=layout1_2, hint=0)

# reset view to fit data
renderView1.ResetCamera()

# hide data in view
Hide(tableToPoints1, renderView1)

# show data in view
tableToPoints1Display = Show(tableToPoints1, renderView1, 'GeometryRepresentation')

# reset view to fit data
renderView1.ResetCamera()

# hide data in view
Hide(tableToPoints1, renderView1)

# show data in view
tableToPoints1Display = Show(tableToPoints1, renderView1, 'GeometryRepresentation')

# reset view to fit data
renderView1.ResetCamera()

# set active source
SetActiveSource(tableToPoints1)

# create a new 'Glyph'
glyph1 = Glyph(registrationName='Glyph1', Input=tableToPoints1,
    GlyphType='Arrow')
glyph1.OrientationArray = ['POINTS', 'No orientation array']
glyph1.ScaleArray = ['POINTS', 'No scale array']
glyph1.ScaleFactor = 0.0108
glyph1.GlyphTransform = 'Transform2'

# show data in view
glyph1Display = Show(glyph1, renderView1, 'GeometryRepresentation')

# trace defaults for the display properties.
glyph1Display.Representation = 'Surface'
glyph1Display.ColorArrayName = [None, '']
glyph1Display.SelectTCoordArray = 'None'
glyph1Display.SelectNormalArray = 'None'
glyph1Display.SelectTangentArray = 'None'
glyph1Display.OSPRayScaleFunction = 'PiecewiseFunction'
glyph1Display.SelectOrientationVectors = 'None'
glyph1Display.ScaleFactor = 0.011880000308156015
glyph1Display.SelectScaleArray = 'None'
glyph1Display.GlyphType = 'Arrow'
glyph1Display.GlyphTableIndexArray = 'None'
glyph1Display.GaussianRadius = 0.0005940000154078007
glyph1Display.SetScaleArray = [None, '']
glyph1Display.ScaleTransferFunction = 'PiecewiseFunction'
glyph1Display.OpacityArray = [None, '']
glyph1Display.OpacityTransferFunction = 'PiecewiseFunction'
glyph1Display.DataAxesGrid = 'GridAxesRepresentation'
glyph1Display.PolarAxes = 'PolarAxesRepresentation'

# update the view to ensure updated data information
renderView1.Update()

# hide data in view
Hide(tableToPoints1, renderView1)

# Properties modified on glyph1
glyph1.GlyphType = 'Box'

# update the view to ensure updated data information
renderView1.Update()

# change solid color
glyph1Display.AmbientColor = [0.9686274509803922, 0.9686274509803922, 0.9686274509803922]
glyph1Display.DiffuseColor = [0.9686274509803922, 0.9686274509803922, 0.9686274509803922]

# Properties modified on glyph1Display
glyph1Display.Opacity = 0.9

# Properties modified on glyph1Display
glyph1Display.Opacity = 0.8

# Properties modified on glyph1Display
glyph1Display.Opacity = 0.7

# Properties modified on glyph1Display
glyph1Display.Opacity = 0.6

# Properties modified on glyph1Display
glyph1Display.Opacity = 0.5

# Properties modified on glyph1Display
glyph1Display.Opacity = 0.4

# Properties modified on glyph1Display
glyph1Display.Opacity = 0.3

# Properties modified on glyph1Display
glyph1Display.Opacity = 0.2

# Properties modified on glyph1Display
glyph1Display.Opacity = 0.1

# Properties modified on glyph1
glyph1.ScaleFactor = 0.006048000000000001

# update the view to ensure updated data information
renderView1.Update()

# Properties modified on glyph1
glyph1.ScaleFactor = 0.002268
glyph1.MaximumNumberOfSamplePoints = 10000

# update the view to ensure updated data information
renderView1.Update()

# Properties modified on glyph1
glyph1.ScaleFactor = 0.0033480000000000003

# update the view to ensure updated data information
renderView1.Update()


'''The loop'''
for jj in range(0,simu_num,1):
    foldername = folder + str(jj).zfill(5) + '\\'
    
    for ii in range(0,simu_iter,iter_gap):
        filename = str(ii).zfill(5)
        ####
        # create a new 'CSV Reader'
        a00000csv = CSVReader(registrationName='00000.csv', FileName=[foldername + filename + '.csv'])
        
        # Create a new 'SpreadSheet View'
        spreadSheetView1 = CreateView('SpreadSheetView')
        spreadSheetView1.ColumnToSort = ''
        spreadSheetView1.BlockSize = 1024
        
        # show data in view
        a00000csvDisplay = Show(a00000csv, spreadSheetView1, 'SpreadSheetRepresentation')
        
        # add view to a layout so it's visible in UI
        AssignViewToLayout(view=spreadSheetView1, layout=layout1_2, hint=0)
        
        # update the view to ensure updated data information
        renderView1.Update()
        
        # create a new 'Table To Points'
        tableToPoints2 = TableToPoints(registrationName='TableToPoints2', Input=a00000csv)
        tableToPoints2.XColumn = 'k'
        tableToPoints2.YColumn = 'k'
        tableToPoints2.ZColumn = 'k'
        
        # Properties modified on tableToPoints2
        tableToPoints2.XColumn = 'x'
        tableToPoints2.YColumn = 'y'
        tableToPoints2.ZColumn = 'z'
        
        # show data in view
        tableToPoints2Display = Show(tableToPoints2, spreadSheetView1, 'SpreadSheetRepresentation')
        
        # hide data in view
        Hide(a00000csv, spreadSheetView1)
        
        # update the view to ensure updated data information
        spreadSheetView1.Update()
        
        # hide data in view
        Hide(tableToPoints2, spreadSheetView1)
        
        # create a new 'Glyph'
        glyph2 = Glyph(registrationName='Glyph2', Input=tableToPoints2,
            GlyphType='Arrow')
        glyph2.OrientationArray = ['POINTS', 'No orientation array']
        glyph2.ScaleArray = ['POINTS', 'No scale array']
        glyph2.ScaleFactor = 0.0008
        glyph2.GlyphTransform = 'Transform2'
        
        # Properties modified on glyph2
        glyph2.GlyphType = 'Sphere'
        
        # show data in view
        glyph2Display = Show(glyph2, spreadSheetView1, 'SpreadSheetRepresentation')
        
        # update the view to ensure updated data information
        spreadSheetView1.Update()
        
        # set active view
        SetActiveView(renderView1)
        
        # set active source
        SetActiveSource(glyph2)
        
        # show data in view
        glyph2Display_1 = Show(glyph2, renderView1, 'GeometryRepresentation')
        
        # trace defaults for the display properties.
        glyph2Display_1.Representation = 'Surface'
        glyph2Display_1.ColorArrayName = [None, '']
        glyph2Display_1.SelectTCoordArray = 'None'
        glyph2Display_1.SelectNormalArray = 'Normals'
        glyph2Display_1.SelectTangentArray = 'None'
        glyph2Display_1.OSPRayScaleArray = 'Normals'
        glyph2Display_1.OSPRayScaleFunction = 'PiecewiseFunction'
        glyph2Display_1.SelectOrientationVectors = 'None'
        glyph2Display_1.ScaleFactor = 0.0008799999952316285
        glyph2Display_1.SelectScaleArray = 'None'
        glyph2Display_1.GlyphType = 'Arrow'
        glyph2Display_1.GlyphTableIndexArray = 'None'
        glyph2Display_1.GaussianRadius = 4.399999976158142e-05
        glyph2Display_1.SetScaleArray = ['POINTS', 'Normals']
        glyph2Display_1.ScaleTransferFunction = 'PiecewiseFunction'
        glyph2Display_1.OpacityArray = ['POINTS', 'Normals']
        glyph2Display_1.OpacityTransferFunction = 'PiecewiseFunction'
        glyph2Display_1.DataAxesGrid = 'GridAxesRepresentation'
        glyph2Display_1.PolarAxes = 'PolarAxesRepresentation'
        
        # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
        glyph2Display_1.ScaleTransferFunction.Points = [-0.9749279022216797, 0.0, 0.5, 0.0, 0.9749279022216797, 1.0, 0.5, 0.0]
        
        # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
        glyph2Display_1.OpacityTransferFunction.Points = [-0.9749279022216797, 0.0, 0.5, 0.0, 0.9749279022216797, 1.0, 0.5, 0.0]
        
        # change solid color
        glyph2Display_1.AmbientColor = [1.0, 0.0, 0.0]
        glyph2Display_1.DiffuseColor = [1.0, 0.0, 0.0]
        
        # Properties modified on glyph2
        glyph2.ScaleFactor = 0.002
        
        # update the view to ensure updated data information
        renderView1.Update()
        
        # update the view to ensure updated data information
        spreadSheetView1.Update()
        
        # Properties modified on glyph2Display_1
        glyph2Display_1.Specular = 0.0
        
        # Properties modified on renderView1
        renderView1.CenterAxesVisibility = 1
        
        # Properties modified on renderView1
        renderView1.CenterAxesVisibility = 0
        
        # Properties modified on renderView1.AxesGrid
        renderView1.AxesGrid.Visibility = 1
        
        # Properties modified on renderView1
        renderView1.CenterAxesVisibility = 1
        
        # Properties modified on renderView1
        renderView1.CenterAxesVisibility = 0
        
        # Properties modified on renderView1
        renderView1.CenterAxesVisibility = 1
        
        # Properties modified on renderView1
        renderView1.OrientationAxesVisibility = 0
        
        # Properties modified on renderView1
        renderView1.OrientationAxesVisibility = 1
        
        # Properties modified on renderView1
        renderView1.HiddenLineRemoval = 1
        
        # Properties modified on renderView1
        renderView1.HiddenLineRemoval = 0
        
        # Properties modified on renderView1
        renderView1.CameraParallelProjection = 1
        
        # Properties modified on renderView1
        renderView1.CameraParallelProjection = 0
        
        # Properties modified on renderView1
        renderView1.CameraParallelProjection = 1
        
        # Properties modified on renderView1
        renderView1.CameraParallelProjection = 0
        
        # Properties modified on renderView1
        renderView1.CameraParallelProjection = 1
        
        # Properties modified on renderView1
        renderView1.CameraParallelProjection = 0
        
        # Properties modified on renderView1
        renderView1.EnableRayTracing = 1
        
        # Properties modified on renderView1
        renderView1.EnableRayTracing = 0
        
        # set active view
        SetActiveView(spreadSheetView1)
        
        # destroy spreadSheetView1
        Delete(spreadSheetView1)
        del spreadSheetView1
        
        # close an empty frame
        layout1_2.Collapse(2)
        
        # set active view
        SetActiveView(renderView1)
        
        # reset view to fit data
        renderView1.ResetCamera()
        
        # reset view to fit data
        renderView1.ResetCamera()
        
        # layout/tab size in pixels
        layout1_2.SetSize(1343, 739)
        
        # current camera placement for renderView1
        renderView1.CameraPosition = [0.0, -0.31145252861999295, 0.07979543540525197]
        renderView1.CameraFocalPoint = [0.0, 0.00425438025168239, 0.024127789375106956]
        renderView1.CameraViewUp = [0.0, 0.1736481776669304, 0.9848077530122081]
        renderView1.CameraParallelScale = 0.08297148396375655
        
        # save screenshot
        SaveScreenshot(foldername+filename+'.bmp', renderView1, ImageResolution=[1343, 739])
        
        '''!!!!!!!!!!delete'''
        # destroy glyph2
        # Delete(glyph2)
        # del glyph2
        
        # # set active source
        # SetActiveSource(a00000csv)
        
        # # destroy tableToPoints2
        # Delete(tableToPoints2)
        # del tableToPoints2
        
        # # destroy a00000csv
        # Delete(a00000csv)
        # del a00000csv

#================================================================
# addendum: following script captures some of the application
# state to faithfully reproduce the visualization during playback
#================================================================

#--------------------------------
# saving layout sizes for layouts

# layout/tab size in pixels
layout1_2.SetSize(1343, 739)

#-----------------------------------
# saving camera placements for views

# current camera placement for renderView1
renderView1.CameraPosition = [0.0, -0.31145252861999295, 0.07979543540525197]
renderView1.CameraFocalPoint = [0.0, 0.00425438025168239, 0.024127789375106956]
renderView1.CameraViewUp = [0.0, 0.1736481776669304, 0.9848077530122081]
renderView1.CameraParallelScale = 0.08297148396375655

#--------------------------------------------
# uncomment the following to render all views
# RenderAllViews()
# alternatively, if you want to write images, you can use SaveScreenshot(...).